<template>
  <div>
    <div>
      <img :src="imgurl" alt="" />
      <p :style="{ backgroundColor: con }" @click="btn">
        {{ name }}
      </p>
    </div>
  </div>
</template>

<script>
export default {
  props: ["imgurl", "name"],
  data() {
    return {
      con: "",
    };
  },
  methods: {
    btn() {
      this.$emit("add", this.name),
        (this.con = `rgba(${Math.floor(Math.random() * 256)},${Math.floor(
          Math.random() * 256
        )},${Math.floor(Math.random() * 256)},${Math.floor(
          Math.random() * 256
        )}`);
    },
  },
};
</script>

<style scoped>
div {
  display: inline-block;
  text-align: center;

  border: 1px solid #000;
}
img {
  width: 400px;
  height: 300px;
}
</style>